home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / SourceCode / MiscKit1.7.1 / MiscKit / Palettes / MiscClipTextPalette / MiscPathFieldInspector.m < prev    next >
Encoding:
Text File  |  1995-07-12  |  5.1 KB  |  191 lines

  1. //
  2. //    MiscPathFieldInspector.m -- IB inspector of MiscPathField
  3. //        Written and Copyright (c) 1995 by Balazs Pataki. 
  4. //                Version 1.0.  All rights reserved.
  5. //
  6. //        This notice may not be removed from this source code.
  7. //
  8. //    This object is included in the MiscKit by permission from the author
  9. //    and its use is governed by the MiscKit license, found in the file
  10. //    "LICENSE.rtf" in the MiscKit distribution.  Please refer to that file
  11. //    for a list of all applicable permissions and restrictions.
  12. //    
  13.  
  14. // Most of the code in this inspector is borrowed form  Mike Ferris's 
  15. // MORegexTextCellInspector of MOKit
  16. // Mike Ferris, Copyright 1993, all rights reserved.
  17.  
  18. #import "MiscPathFieldInspector.h"
  19. #import "MiscClipText.subproj/MiscPathField.h"
  20. #import <objc/objc-runtime.h>
  21.  
  22. #define CLASS_VERSION    0
  23. #define CLASS_NAME        "MiscPathFieldInspector"
  24.  
  25.  
  26. #define BG_NONE_TAG        0
  27. #define BG_BLACK_TAG    1
  28. #define BG_DKGRAY_TAG    2
  29. #define BG_LTGRAY_TAG    3
  30. #define BG_WHITE_TAG    4
  31.  
  32. #define TG_BLACK_TAG    0
  33. #define TG_DKGRAY_TAG    1
  34. #define TG_LTGRAY_TAG    2
  35. #define TG_WHITE_TAG    3
  36.  
  37. #define ALIGN_LEFT_TAG        0
  38. #define ALIGN_CENTER_TAG    1
  39. #define ALIGN_RIGHT_TAG        2
  40.  
  41. #define BORDER_NONE_TAG        0
  42. #define BORDER_LINE_TAG        1
  43. #define BORDER_BEZEL_TAG    2
  44.  
  45.  
  46. #define NIB_TYPE                            "nib"
  47. #define NIB_NAME                            "MiscPathFieldInspector"
  48.  
  49.  
  50. @implementation MiscPathFieldInspector
  51.  
  52. + initialize
  53. // Set the version.
  54. {
  55.     if (self == objc_lookUpClass(CLASS_NAME))  {
  56.         [self setVersion:CLASS_VERSION];
  57.     }
  58.     return self;
  59. }
  60.  
  61. - init
  62. // Load our nib file.
  63. {
  64.     char buf[MAXPATHLEN+1];
  65.     id bundle;
  66.     
  67.     [super init];
  68.     
  69.     // load our nib file.
  70.     bundle = [NXBundle bundleForClass:[self class]];
  71.     [bundle getPath:buf forResource:NIB_NAME ofType:NIB_TYPE];
  72.     [NXApp loadNibFile:buf owner:self withNames:NO fromZone:[self zone]];
  73.     
  74.     return self;
  75. }
  76.  
  77. - ok:sender
  78. // set the text field-ish stuff and the allowEmptyString attribute.  
  79. // The patternButtonAction takes care of the regex stuff.  The 
  80. // optionCheckboxAction takes care of editable, selectable, scrollable.
  81. {
  82.     int bgTag = [backgroundGrayMatrix selectedTag];
  83.     int tgTag = [textGrayMatrix selectedTag];
  84.     int alTag = [alignmentMatrix selectedTag];
  85.     int boTag = [borderMatrix selectedTag];
  86.         
  87.     if (bgTag == BG_NONE_TAG)  {
  88.         [object setBackgroundGray:-1.0];
  89.     }  else if (bgTag == BG_BLACK_TAG)  {
  90.         [object setBackgroundGray:NX_BLACK];
  91.     }  else if (bgTag == BG_DKGRAY_TAG)  {
  92.         [object setBackgroundGray:NX_DKGRAY];
  93.     }  else if (bgTag == BG_LTGRAY_TAG)  {
  94.         [object setBackgroundGray:NX_LTGRAY];
  95.     }  else  {
  96.         [object setBackgroundGray:NX_WHITE];
  97.     }
  98.     if (tgTag == TG_BLACK_TAG)  {
  99.         [object setTextGray:NX_BLACK];
  100.     }  else if (tgTag == TG_DKGRAY_TAG)  {
  101.         [object setTextGray:NX_DKGRAY];
  102.     }  else if (tgTag == TG_LTGRAY_TAG)  {
  103.         [object setTextGray:NX_LTGRAY];
  104.     }  else  {
  105.         [object setTextGray:NX_WHITE];
  106.     }
  107.     if (alTag == ALIGN_LEFT_TAG)  {
  108.         [object setAlignment:NX_LEFTALIGNED];
  109.     }  else if (alTag == ALIGN_CENTER_TAG)  {
  110.         [object setAlignment:NX_CENTERED];
  111.     }  else  {
  112.         [object setAlignment:NX_RIGHTALIGNED];
  113.     }
  114.     if (boTag == BORDER_NONE_TAG)  {
  115.         [object setBordered:NO];
  116.         [object setBezeled:NO];
  117.     }  else if (boTag == BORDER_LINE_TAG)  {
  118.         [object setBordered:YES];
  119.     }  else  {
  120.         [object setBezeled:YES];
  121.     }
  122.  
  123.     [object setTag:[tagForm intValueAt:0]];
  124.  
  125.     // My settings
  126.     [object setReplaceHomeWithTilde:[replaceHomeButton state]];
  127.  
  128.     return [super ok:sender];
  129. }
  130.  
  131. - revert:sender
  132. // fill in the inspector with the attributes of "object"
  133. {    
  134.     float bg = [object backgroundGray], tg = [object textGray];
  135.     int alignment = [object alignment];
  136.     BOOL isBordered = [object isBordered], isBezeled = [object isBezeled];
  137.     
  138.     if (bg < 0)  {
  139.         [backgroundGrayMatrix selectCellAt:0:BG_NONE_TAG];
  140.     }  else  if ((bg >= 0) && (bg < .2))  {
  141.         [backgroundGrayMatrix selectCellAt:0:BG_BLACK_TAG];
  142.     }  else  if ((bg >= .2) && (bg < .45))  {
  143.         [backgroundGrayMatrix selectCellAt:0:BG_DKGRAY_TAG];
  144.     }  else  if ((bg >= .45) && (bg < .8))  {
  145.         [backgroundGrayMatrix selectCellAt:0:BG_LTGRAY_TAG];
  146.     }  else  if (bg >= .8)  {
  147.         [backgroundGrayMatrix selectCellAt:0:BG_WHITE_TAG];
  148.     }
  149.     [backgroundGrayMatrix display];
  150.     if (tg < .2)  {
  151.         [textGrayMatrix selectCellAt:0:TG_BLACK_TAG];
  152.     }  else  if ((tg >= .2) && (tg < .45))  {
  153.         [textGrayMatrix selectCellAt:0:TG_DKGRAY_TAG];
  154.     }  else  if ((tg >= .45) && (tg < .8))  {
  155.         [textGrayMatrix selectCellAt:0:TG_LTGRAY_TAG];
  156.     }  else  if (tg >= .8)  {
  157.         [textGrayMatrix selectCellAt:0:TG_WHITE_TAG];
  158.     }
  159.     [textGrayMatrix display];
  160.     if (alignment == NX_LEFTALIGNED)  {
  161.         [alignmentMatrix selectCellAt:0:ALIGN_LEFT_TAG];
  162.     }  else if (alignment == NX_CENTERED)  {
  163.         [alignmentMatrix selectCellAt:0:ALIGN_CENTER_TAG];
  164.     }  else  {
  165.         [alignmentMatrix selectCellAt:0:ALIGN_RIGHT_TAG];
  166.     }
  167.     [alignmentMatrix display];
  168.     if (isBezeled)  {
  169.         [borderMatrix selectCellAt:0:BORDER_BEZEL_TAG];
  170.     }  else if (isBordered)  {
  171.         [borderMatrix selectCellAt:0:BORDER_LINE_TAG];
  172.     }  else  {
  173.         [borderMatrix selectCellAt:0:BORDER_NONE_TAG];
  174.     }
  175.  
  176.     [tagForm setIntValue:[object tag] at:0];
  177.     
  178.     // My settings
  179.     [replaceHomeButton setState:[object doesReplacesHomeWithTilde]];
  180.  
  181.     return [super revert:sender];
  182. }
  183.  
  184. - (BOOL)wantsButtons
  185. // Our inspector does not have OK or Revert buttons.
  186. {
  187.     return NO;
  188. }
  189.  
  190.  
  191. @end